package com.nulldev.util.threading;

import com.nulldev.util.other.Timer;
import com.nulldev.util.threading.v3.ThreadDispatcher;

public class ThreadUtils {
	
	public static void kill(final Thread... threads) {
		for (final Thread t : threads) {
			if (t != null) {
				try {
					if (t.isDaemon()) {
						t.setDaemon(false);
					}
					t.interrupt();
				}catch (Exception e) {}
			}
		}
	}

	public static interface WaitCheck {
		
		public boolean check();
		
	}
	
	public static void wait(final WaitCheck arg, final int ms) {
		final Timer t = new Timer();
		t.start(ThreadDispatcher.instance().getExec());
		while (!t.hasReached(ms)) {
			if (arg.check()) {
				break;
			}
		}
		t.stop();
	}
}
